export default {
  computed: {
    imageUrl() {
      if (this.formData.picture) {
        let prefix = ''
        if (!/http:\/\/|https:\/\//.test(this.formData.picture)) {
          prefix = `${process.env.VUE_APP_BASE_DOMAIN}`
        }
        return prefix + this.formData.picture
      }
      return ''
    }
  },
  methods: {
    onSuccess(data) {
      this.formData.picture = data.imgUrl
    },
    beforeUpload(file) {
      const isJPG = file.type === 'image/jpeg'
      const isLt2M = file.size / 1024 / 1024 < 2

      if (!isJPG) {
        this.$message({ message: '上传图片只能是 JPG 格式!', type: 'error', showClose: true })
      }
      if (!isLt2M) {
        this.$message({ message: '上传图片大小不能超过 2MB!', type: 'error', showClose: true })
      }
      return isJPG && isLt2M
    }
  }
}
